<!--评价学员-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="所在班级" prop="classId">
        <el-select
          v-model="queryParams.classId"
          placeholder="请选择所在班级"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="item in classList"
            :key="item.id"
            :label="item.beOver === '0' ? item.name + '(已结业)' : item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上课日期" prop="classDate">
        <el-date-picker
          v-model="classDate"
          type="daterange"
          range-separator="~"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="classDateRangeChange"
          value-format="YYYY-MM-DD"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="主班老师" prop="teacher">
        <el-select
          v-model="queryParams.teacher"
          placeholder="请选择主班老师"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="item in teacherList"
            :key="item.value"
            :label="
              !item.isJob
                ? item.label + '(已离职)'
                : !item.isTeacher
                ? item.label + '(非授课)'
                : item.label
            "
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="助教老师" prop="assistant">
        <el-select
          v-model="queryParams.assistant"
          placeholder="请选择助教老师"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="item in teacherList"
            :key="item.value"
            :label="
              !item.isJob
                ? item.label + '(已离职)'
                : !item.isTeacher
                ? item.label + '(非授课)'
                : item.label
            "
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">
          搜索
        </el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain @click="handleRecord">
          点评记录
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="plain" plain @click="handleSet">
          设置评分维度
        </el-button>
      </el-col>

      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList">
      </right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="班级名称" align="center" prop="className" />
      <el-table-column label="上课时间" align="center" prop="classDate" />
      <el-table-column label="主班老师" align="center" prop="teacherName" />
      <el-table-column label="助教老师" align="center" prop="assistantName" />
      <el-table-column label="上课内容" align="center" prop="description" />
      <el-table-column label="已评/应评人数" align="center">
        <template #default="scope">
          {{ scope.row.num }}/{{ scope.row.totalNum }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="150"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template #default="scope">
          <el-button link type="primary" @click="handleView(scope.row)">
            查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
  <ScoringDimension ref="setRef" />
  <CommentDetail ref="detailRef" />
  <Record ref="recordRef" />
</template>

<script setup name="CommentStudent">
import { getPeopleList } from "@/api/studentManagement/index.js";
import { getClassListAPI } from "@/api/registrar/class";
import { getEvaluateStudentListAPI } from "@/api/interaction/comment";

import ScoringDimension from "./components/scoringDimension.vue";
import CommentDetail from "./components/commentDetail.vue";
import Record from "./components/record.vue";

const { proxy } = getCurrentInstance();
const loading = ref(false);
const showSearch = ref(true);
const total = ref(0);
const classDate = ref(null);

const list = ref([]);
const teacherList = ref([]);
const classList = ref([]);

const setRef = ref(null);
const detailRef = ref(null);
const recordRef = ref(null);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    classId: "",
    teacher: null,
    assistant: null,
    classStartTime: null,
    classEndTime: null,
  },
});

const { queryParams } = toRefs(data);

// 事件-----------------------------------------------------------------------------------------------------------

function classDateRangeChange(event) {
  classDate.value = event;
  queryParams.value.classStartTime = event ? event[0] : null;
  queryParams.value.classEndTime = event ? event[1] : null;
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
    classId: "",
    teacher: null,
    assistant: null,
    classStartTime: null,
    classEndTime: null,
  };
  classDate.value = null;
  getList();
}

// 点评记录
function handleRecord() {
  recordRef.value.openW();
}

// 设置点评维度
function handleSet() {
  setRef.value.openW();
}

// 查看
function handleView(row) {
  detailRef.value.openW(row);
}

// 方法-----------------------------------------------------------------------------------------------------------
// 获取教师列表
function getTeacherList() {
  loading.value = true;
  getPeopleList({ isTeach: 1 }).then((response) => {
    teacherList.value = response.data;
    loading.value = false;
  });
}

// 班级
function getClassList() {
  loading.value = true;
  getClassListAPI({ pageSize: 9999, pageNum: 1 }).then((response) => {
    classList.value = response.rows;
    loading.value = false;
  });
}

// 列表查询
function getList() {
  loading.value = true;
  getEvaluateStudentListAPI(proxy.addDateRange(queryParams.value, [])).then(
    (response) => {
      list.value = response.rows;
      total.value = response.total;
      loading.value = false;
    }
  );
}

// 初始化-------------------------------------------------------------------------------------------------------
getTeacherList();
getClassList();
getList();
</script>

<style lang="scss" scoped></style>
